<template>
    <div>
        <h2 class="h2"><span>基本信息</span></h2>
        <div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm basic" id="basic" accept-charset="UTF-8">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="姓名：" prop="A003">
                            <el-input v-model="ruleForm.A003" id="A003" placeholder="请输入姓名"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                         <el-form-item label="性别：" prop="A004">
                            <el-radio-group v-model="ruleForm.A004">
                                <el-radio label="男"></el-radio>
                                <el-radio label="女"></el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                       <el-form-item label="民族：" prop="A005">
                            <el-input v-model="ruleForm.A005" id="A005" placeholder="请输入民族"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="身份证号码：" prop="A006">
                            <el-input v-model="ruleForm.A006" id="A006" placeholder="身份证号码"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item class="select2" label="文化程度：" prop="A010">
                            <el-select v-model="ruleForm.A010" placeholder="请选择文化程度">
                                <el-option label="博士" value="博士"></el-option>
                                <el-option label="硕士" value="硕士"></el-option>
                                <el-option label="大学本科" value="大学本科"></el-option>
                                <el-option label="大学专科" value="大学专科"></el-option>
                                <el-option label="中专（中技）" value="中专（中技）"></el-option>
                                <el-option label="高中" value="高中"></el-option>
                                <el-option label="初中及以下" value="初中及以下"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="出生日期：" prop="A007">
                            <el-date-picker v-model="ruleForm.A007" type="date" placeholder="选择日期"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="sanjiliandong">
                    <el-form-item label="户籍所在地：">
                        <linkage @hujisuozaidifn="hujisuozaidifnsss"></linkage>
                    </el-form-item>
                </el-row>
                <el-row :gutter="20" class="sanjiliandong">
                    <el-form-item label="现家庭住址：">
                        <linkage @hujisuozaidifn="hujisuozaidifnsss2"></linkage>
                    </el-form-item>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="详细住址：" prop="xiangxizhuzhi">
                            <el-input v-model="ruleForm.xiangxizhuzhi" id="xiangxizhuzhi" placeholder="请输入姓名"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                         <el-form-item label="电话号码：" prop="A011">
                            <el-input v-model="ruleForm.A011" id="A011" placeholder="请输入电话号码"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item class="select2" label="婚姻状况：" prop="A012">
                            <el-select v-model="ruleForm.A012" placeholder="婚姻状况">
                                <el-option label="未婚" value="未婚"></el-option>
                                <el-option label="已婚" value="已婚"></el-option>
                                <el-option label="离婚" value="离婚"></el-option>
                                <el-option label="丧偶" value="丧偶"></el-option>
                            </el-select>         
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                         <el-form-item class="select2" label="政治面貌：" prop="A013">
                            <el-select v-model="ruleForm.A013" placeholder="政治面貌">
                                <el-option label="中共党员" value="中共党员"></el-option>
                                <el-option label="民主党员" value="民主党员"></el-option>
                                <el-option label="共青团员" value="共青团员"></el-option>
                                <el-option label="群众" value="群众"></el-option>
                            </el-select>               
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="24">
                        <el-form-item label="民主党派名称：">
                            <el-input v-model="ruleForm.A014" id="A014" placeholder="民主党派名称（如有则填）"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">下一步</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
import linkage from '@/components/element/linkage'
import interface_s from '@/api/api.js'
export default {
    data(){
        return {
            ruleForm: { //默认数据
                A003:'',//姓名
                A004:'',//性别
                A005:'',//民族
                A006:'',//身份证号
                A007:'', //出生日期
                A008:'',//户籍所在地
                A009:'',//现家庭住址
                A010:'',//文化程度
                A011:'',//联系电话
                A012:'', //婚姻状况
                A013:'',//政治面貌
                A014:'',//民主党派名称
                xiangxizhuzhi:'',//详细住址
                userID:this.$cookies.get('userID'),
            },
            rules: {  //规则
                A003: [ //姓名
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
                ],
                A004: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                A005:[
                    { required: true, message: '请填写民族', trigger: 'blur' },
                ],
                A006:[ //身份证号
                    {required: true, message: '请填写证件号码', trigger: 'blur' },
                    {pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '证件号码格式有误！', trigger: 'blur'}
                ],
                A007: [ //出生日期
                    { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                ],
                A010:[
                    { required: true, message: '请选择文化程度', trigger: 'change' }
                ],
                A011:[  //请填写手机号码
                    { required: true, message: '请填写手机号码', trigger: 'blur' },
                ],
                A012:[
                    { required: true, message: '请填写婚姻状况', trigger: 'change' },
                ],
                A013:[
                    { required: true, message: '请填写政治面貌', trigger: 'change' },
                ],
                xiangxizhuzhi:[  //详细住址
                    { required: true, message: '请填写详细住址', trigger: 'blur' },
                ],
            },
        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // alert('成功，tuiyishibing!');
                    this.ruleForm.A009 += (','+this.ruleForm.xiangxizhuzhi)
                    console.log(this.ruleForm.A009)
                    console.log(this.ruleForm)
                    let postData = this.$qs.stringify(this.ruleForm);
                    console.log(postData)
                    // 基本信息提交
                    this.$axios.post(this.HOST+interface_s.basic,postData,{
                        headers:{
                            'Content-Type':'application/x-www-form-urlencoded', 
                        }
                    })
                    .then( (response) => {
                        if(response.data.code==0){
                            this.$alert('填写成功！', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    this.$emit('submitfn',2)
                                }
                            })
                        }else{
                            this.$alert('填写失败身份证号码有误 或重复', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                   
                                }
                            })
                        }
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        hujisuozaidifnsss(value){
            let arry = value.join(",")
            this.ruleForm.A008 = arry
            console.log(this.ruleForm.A008)
        },
        hujisuozaidifnsss2(value){
            let arry = value.join(",")
            this.ruleForm.A009 = arry
            console.log(this.ruleForm.A008)
        }
    },
    components:{
        linkage,
    },
    created(){
        console.log(this.ruleForm.userID)
    }
}
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
}
.el-row:last-child {
    margin-bottom: 0;
}
</style>